#include <stdio.h>
#include "sudoku_config.h"

char data[3][3][3][3];	   /* data of current sudoku table */
char poss[3][3][3][3][9];  /* possibilities of current sudoku table */

/* init */
bool debug = NO;
bool dummy = YES;
bool simple = NO;
bool arranged = NO;
bool collected = NO;
bool put_value = NO;
bool error = NO;
bool do_arrange_poss = NO;
bool do_collect_poss = YES;
bool do_assign_data = NO;


int get_initial_data()
{
    int i, j, k, l;
    
    printf("Enter Initial Data of Sudoku:\n");
    for (i = 0; i < 3; i++) {
	for (j = 0; j < 3; j++) {
	    for (k = 0; k < 3; k++) {
		for (l = 0; l < 3; l++) {
		    printf("data[%d][%d][%d][%d] : ", i, j, k, l);
		    scanf("\n%d", &data[i][j][k][l]);
		}
	    }
	}
    }
    return 0;
}

int show_data(char way)
{
    int i, j, k, l;
    
    printf("Current Data of Sudoku:\n");
    switch (way) {
    case HAR:			/* to navigate horizontally */
	printf("+-----------+----------+----------+\n");
	for (i = 0; i < 3; i++) {
	    for (j = 0; j < 3; j++) {
		printf("| ");
		for (k = 0; k < 3; k++) {
		    for (l = 0; l < 3; l++) {
			if (data[i][j][k][l] == 0)
			    printf("   ");
			else
			    printf(" %d ", data[i][j][k][l]);
		    }
		    printf(" |");
		}
		printf("\n");
	    }
	    printf("+-----------+----------+----------+\n");
	}
	break;
    case VER:			/* to navigate vertically */
	printf("+-----------+----------+----------+\n");
	for (k = 0; k < 3; k++) {
	    for (l = 0; l < 3; l++) {
		printf("| ");
		for (i = 0; i < 3; i++) {
		    for (j = 0; j < 3; j++) {
			if (data[i][j][k][l] == 0)
			    printf("     ");
			else
			    printf("  %d  ", data[i][j][k][l]);
		    }
		    printf(" | ");
		}
		printf("\n");
	    }
	    printf("+-----------+----------+----------+\n");
	}
	break;
    case PAR:			/* to navigate as paragraph */
	printf("+-----------+----------+----------+\n");
	for (i = 0; i < 3; i++) {
	    for (k = 0; k < 3; k++) {
		printf("| ");
		for (j = 0; j < 3; j++) {
		    for (l = 0; l < 3; l++) {
			if (data[i][j][k][l] == 0)
			    printf("     ");
			else
			    printf("  %d  ", data[i][j][k][l]);
		    }
		    printf(" | ");
		}
		printf("\n");
	    }
	    printf("+-----------+----------+----------+\n");
	}
	break;
    }
    return 0;
}

void show_struct()
{
    int i, j, k, l;
    printf("+-----------+----------+----------+\n");
    for (i = 0; i < 3; i++) {
	for (j = 0; j < 3; j++) {
	    printf("| ");
	    for (k = 0; k < 3; k++) {
		for (l = 0; l < 3; l++) {
		    printf("%d%d%d%d  ", i, j, k, l);
		}
		printf(" | ");
	    }
	    printf("\n");
	}
	printf("+-----------+----------+----------+\n");
    }
}

void show_struct_poss()
{
    int i, j, k, l, m;
    printf("+-----------+----------+----------+\n");
    for (i = 0; i < 3; i++) {
	for (j = 0; j < 3; j++) {
	    printf("| ");
	    for (k = 0; k < 3; k++) {
		for (l = 0; l < 3; l++) {
		    for (m = 0; /* poss[i][j][k][l][m] &&  */(m < 9); m++) {
			if (poss[i][j][k][l][m] == 0) {
			    printf(" ", poss[i][j][k][l][m]);
			} else {
			    printf("%d", poss[i][j][k][l][m]);
			}
		    }
		    printf("  ");
		}
		printf(" | ");
	    }
	    printf("\n");
	}
	printf("+-----------+----------+----------+\n");
    }
}

void show_poss()
{
    int i, j, k, l, m;

    for (i = 0; i < 3; i++) {
	for (j = 0; j < 3; j++) {
	    for (k = 0; k < 3; k++) {
		for (l = 0; l < 3; l++) {
		    printf("poss[%d][%d][%d][%d] : ", i, j, k, l);  
		    for (m = 0; m < 9; m++) {
			if (poss[i][j][k][l][m] == 0) {
			    printf("   ");
			    continue;
			}
			printf(" %d ",	poss[i][j][k][l][m]);
		    }
		    printf("\n");
		}
	    }
	}
    }
}
void assign_sample()
{
    
    if (simple) {
	data[0][0][0][0] = 8;
	data[0][0][0][1] = 4;
	data[0][0][0][2] = 0;
	data[0][0][1][0] = 9;
	data[0][0][1][1] = 0;
	data[0][0][1][2] = 0;
	data[0][0][2][0] = 0;
	data[0][0][2][1] = 0;
	data[0][0][2][2] = 0;
	data[0][1][0][0] = 0;
	data[0][1][0][1] = 0;
	data[0][1][0][2] = 5;
	data[0][1][1][0] = 8;
	data[0][1][1][1] = 7;
	data[0][1][1][2] = 0;
	data[0][1][2][0] = 1;
	data[0][1][2][1] = 0;
	data[0][1][2][2] = 0;
	data[0][2][0][0] = 0;
	data[0][2][0][1] = 0;
	data[0][2][0][2] = 0;
	data[0][2][1][0] = 0;
	data[0][2][1][1] = 0;
	data[0][2][1][2] = 0;
	data[0][2][2][0] = 0;
	data[0][2][2][1] = 0;
	data[0][2][2][2] = 2;
	data[1][0][0][0] = 1;
	data[1][0][0][1] = 0;
	data[1][0][0][2] = 8;
	data[1][0][1][0] = 0;
	data[1][0][1][1] = 0;
	data[1][0][1][2] = 0;
	data[1][0][2][0] = 0;
	data[1][0][2][1] = 3;
	data[1][0][2][2] = 7;
	data[1][1][0][0] = 0;
	data[1][1][0][1] = 0;
	data[1][1][0][2] = 7;
	data[1][1][1][0] = 2;
	data[1][1][1][1] = 0;
	data[1][1][1][2] = 1;
	data[1][1][2][0] = 5;
	data[1][1][2][1] = 0;
	data[1][1][2][2] = 0;
	data[1][2][0][0] = 9;
	data[1][2][0][1] = 6;
	data[1][2][0][2] = 0;
	data[1][2][1][0] = 0;
	data[1][2][1][1] = 0;
	data[1][2][1][2] = 0;
	data[1][2][2][0] = 8;
	data[1][2][2][1] = 0;
	data[1][2][2][2] = 1;
	data[2][0][0][0] = 3;
	data[2][0][0][1] = 0;
	data[2][0][0][2] = 0;
	data[2][0][1][0] = 0;
	data[2][0][1][1] = 0;
	data[2][0][1][2] = 0;
	data[2][0][2][0] = 0;
	data[2][0][2][1] = 0;
	data[2][0][2][2] = 0;
	data[2][1][0][0] = 0;
	data[2][1][0][1] = 0;
	data[2][1][0][2] = 1;
	data[2][1][1][0] = 0;
	data[2][1][1][1] = 6;
	data[2][1][1][2] = 7;
	data[2][1][2][0] = 4;
	data[2][1][2][1] = 0;
	data[2][1][2][2] = 0;
	data[2][2][0][0] = 0;
	data[2][2][0][1] = 0;
	data[2][2][0][2] = 0;
	data[2][2][1][0] = 0;
	data[2][2][1][1] = 0;
	data[2][2][1][2] = 4;
	data[2][2][2][0] = 0;
	data[2][2][2][1] = 5;
	data[2][2][2][2] = 3;
    } else {

	data[0][0][0][0] = 0;
	data[0][0][0][1] = 0;
	data[0][0][0][2] = 0;
	data[0][0][1][0] = 0;
	data[0][0][1][1] = 6;
	data[0][0][1][2] = 1;
	data[0][0][2][0] = 0;
	data[0][0][2][1] = 0;
	data[0][0][2][2] = 5;
	data[0][1][0][0] = 0;
	data[0][1][0][1] = 3;
	data[0][1][0][2] = 0;
	data[0][1][1][0] = 0;
	data[0][1][1][1] = 0;
	data[0][1][1][2] = 0;
	data[0][1][2][0] = 0;
	data[0][1][2][1] = 0;
	data[0][1][2][2] = 9;
	data[0][2][0][0] = 0;
	data[0][2][0][1] = 4;
	data[0][2][0][2] = 0;
	data[0][2][1][0] = 0;
	data[0][2][1][1] = 0;
	data[0][2][1][2] = 3;
	data[0][2][2][0] = 1;
	data[0][2][2][1] = 0;
	data[0][2][2][2] = 0;

	data[1][0][0][0] = 7;
	data[1][0][0][1] = 8;
	data[1][0][0][2] = 0;
	data[1][0][1][0] = 3;
	data[1][0][1][1] = 0;
	data[1][0][1][2] = 0;
	data[1][0][2][0] = 0;
	data[1][0][2][1] = 5;
	data[1][0][2][2] = 2;
	data[1][1][0][0] = 0;
	data[1][1][0][1] = 0;
	data[1][1][0][2] = 2;
	data[1][1][1][0] = 0;
	data[1][1][1][1] = 0;
	data[1][1][1][2] = 0;
	data[1][1][2][0] = 9;
	data[1][1][2][1] = 0;
	data[1][1][2][2] = 0;
	data[1][2][0][0] = 5;
	data[1][2][0][1] = 9;
	data[1][2][0][2] = 0;
	data[1][2][1][0] = 0;
	data[1][2][1][1] = 0;
	data[1][2][1][2] = 8;
	data[1][2][2][0] = 0;
	data[1][2][2][1] = 1;
	data[1][2][2][2] = 6;

	data[2][0][0][0] = 0;
	data[2][0][0][1] = 0;
	data[2][0][0][2] = 7;
	data[2][0][1][0] = 1;
	data[2][0][1][1] = 0;
	data[2][0][1][2] = 0;
	data[2][0][2][0] = 0;
	data[2][0][2][1] = 9;
	data[2][0][2][2] = 0;
	data[2][1][0][0] = 6;
	data[2][1][0][1] = 0;
	data[2][1][0][2] = 0;
	data[2][1][1][0] = 0;
	data[2][1][1][1] = 0;
	data[2][1][1][2] = 0;
	data[2][1][2][0] = 0;
	data[2][1][2][1] = 7;
	data[2][1][2][2] = 0;
	data[2][2][0][0] = 9;
	data[2][2][0][1] = 0;
	data[2][2][0][2] = 0;
	data[2][2][1][0] = 6;
	data[2][2][1][1] = 2;
	data[2][2][1][2] = 0;
	data[2][2][2][0] = 0;
	data[2][2][2][1] = 0;
	data[2][2][2][2] = 0;
    }    
}
